package com.dw.dwdzcommerce.view.details.lis;

import com.dw.dwdzcommerce.R;
import com.dw.dwdzcommerce.base.activity.BaseActivity;
import com.dw.dwdzcommerce.entity.AdPage;
import com.dw.dwdzcommerce.entity.MainContentEntity;
import com.dw.dwdzcommerce.entity.Shop;
import com.dw.dwdzcommerce.tools.commons.ArrayUtil;
import com.dw.dwdzcommerce.view.mainContent.SelectLayout;
import com.dw.dwdzcommerce.view.mainContent.ad.ADPagerLayout;
import com.dw.dwdzcommerce.view.mainContent.list.MainContentListLayout;
import com.dw.dwdzcommerce.view.mainContent.list.MainContentListLayout.OnContentClickListener;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Toast;

public class DetailsListAdapter extends BaseAdapter {

	private static final String TAG = "MainContentListAdapter";
	private Shop[] mShops;
	private Context mContext;

	public DetailsListAdapter(MainContentEntity mData, ADPagerLayout pagerLayout, SelectLayout mSelectLayout,
			Context mContext) {
		this.mContext = mContext;
		mData.getAdPages();
		mShops = mData.getShops();
	}

	public DetailsListAdapter(MainContentEntity mData, BaseActivity mContext) {
//		ADPagerLayout pagerLayout = new ADPagerLayout();
//		pagerLayout.initModule(mContext);
//		SelectLayout mSelectLayout = new SelectLayout();
//		mSelectLayout.initModule(mContext);
		mData.getAdPages();
		mShops = mData.getShops();
		this.mContext = mContext;

	}

	@Override
	public int getCount() {
		return mShops.length ;
	}

	@Override
	public Object getItem(int position) {
//		if (position == 0) {
//			return mAdPages;
//		}
//		if (position == 1) {
//
//			return mSelectLayout.getView();
//		}

		return mShops[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// if (position == 0) {
		// convertView = mPageLayout.getADView();
		// } else if (position == 1) {
		// convertView = mSelectLayout.getView();
		// } else {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_fragment_main_content_lis, null);
		}
		MainContentListLayout mListLayout = new MainContentListLayout();
		// convertView =
		// LayoutInflater.from(mContext).inflate(R.layout.item_fragment_main_content_lis,
		// null);
		mListLayout.setmListener(new OnContentClickListener() {
			@Override
			public void onFocus(View view, int mShopId) {
				Toast.makeText(mContext, "" + view.getTag() + " mShopId=" + mShopId, Toast.LENGTH_SHORT).show();

			}

			@Override
			public void onLocClick(View view, int mShopId) {
				Toast.makeText(mContext, " mShopId=" + mShopId, Toast.LENGTH_SHORT).show();
			}
		});
//		position -= 2;
		mListLayout.initModule(convertView, (FragmentActivity) mContext);
		mListLayout.setShopLoc(mShops[position].getAddress());
		mListLayout.setShopName(mShops[position].getShopName());
		mListLayout.setShopRule(mShops[position].getActRules());
		mListLayout.setShopAvator(mShops[position].getShopAvator(), mContext);
		mListLayout.setShopContent(mShops[position].getImages());
		mListLayout.setmShopId(mShops[position].getShopId());
		mListLayout.setPhone(mShops[position].getPhone());
		// }
		return convertView;
	}

	class ADPagerHolder {

	}

	class IntroViewHolder {

	}

	class ShopViewHolder {

	}

}
